package servlet;

import bean.Result;
import biz.ItemBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryQXTServlet", value = "/QueryQXTServlet.s")
public class QueryQXTServlet extends HttpServlet {
    private ItemBiz biz = new ItemBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 得到月份数组
        Result result;
        try {
            String[] months = request.getParameterValues("months");
            List<List> list = new ArrayList<>();
            for (int i = 0; i < months.length; i++){
                list.add(biz.queryQXT(months[i]));
            }
            result = new Result(1, "查询成功!", list);
        } catch (Exception e) {
            e.printStackTrace();
            result = new Result(0, "查询失败!", null);
        }
        String json = new Gson().toJson(result);
        response.getWriter().append(json);

    }
}
